package gwtadmin.client.wsdltree;

import com.google.gwt.user.client.rpc.IsSerializable;

public class WtPortType extends Wt implements IsSerializable {
	
	public WtPortType() {
		super();
	}
	
	public WtPortType(QName qname, String url, WtOperation[] operations) {
		super(qname);
		this.url = url;
		this.operations = operations;
	}
	
	public WtOperation getOperation(QName qname) {
		for (WtOperation op : operations) {
			if (op.qname.equals(qname))
				return op;
		}
		return null;
	}
	
	public String toString() {
		String res = "public interface " + qname.name + " {\n";
		
		for (WtOperation op : operations) {
			String msgInput = "";
			String msgOuString = "void";
			String msgFaults = "";
			
			if (op.msgInput != null) {
				msgInput = op.msgInput.qname.name;
			}
			
			if (op.msgOutput != null) {
				msgOuString = op.msgOutput.qname.name;
			}
			
			if (op.msgFaults != null) {
				msgFaults = " throws ";
				
				for (int i = 0; i < op.msgFaults.length; i++) {
					msgFaults += op.msgFaults[i].qname.name;
					
					if (i < op.msgFaults.length-1)
						msgFaults += ",";
				}
			}
			
			res += "    " + msgOuString + " " + op.qname.name + "(" + msgInput + ")" + msgFaults + ";\n";
		}
		
		res += "}\n";
		
		return res;
	}

//	public QName Wt.qname;
	public String url;
	public WtOperation[] operations;
}
